#define _GNU_SOURCE
#include "command.h"

int _sysinfo(char *argv[])
{
	/* check the number of cmd-line parameters is correct */
	int argc = 0;
	for (char **ptr = argv; *ptr != NULL; ptr++)
		argc++;

	if (argc != 1) {
		fprintf(stderr, "Usage: sysinfo\n");
		return -1;
	}

	struct utsname uts;

	if (uname(&uts) == -1) {
		fprintf(stderr, "sysinfo error: uname\n");
		return -1;
	}

	printf("\n\t%s----- SYSTEM INFO -----%s\n", CYAN, RESET);
	printf("\t%sNode name:%s   %s\n", YELLOW, RESET, uts.nodename);
	printf("\t%sSystem name:%s %s\n", YELLOW, RESET, uts.sysname);
	printf("\t%sRelease:%s     %s\n", YELLOW, RESET, uts.release);
	printf("\t%sVersion:%s     %s\n", YELLOW, RESET, uts.version);
	printf("\t%sMachine:%s     %s\n", YELLOW, RESET, uts.machine);
#ifdef _GNU_SOURCE
	printf("\t%sDomain name:%s %s\n", YELLOW, RESET, uts.domainname);
#endif
	printf("\n");
	
	return 0;
}
